package tp.pr5.mv.instructions.stack;

import tp.pr5.mv.Instruction;
import tp.pr5.mv.Memory;
import tp.pr5.mv.Opcode;
import tp.pr5.mv.OperandStack;
import tp.pr5.mv.ProgramCounter;
import tp.pr5.mv.inout.InMethod;
import tp.pr5.mv.inout.OutMethod;
import tp.pr5.mv.traps.MVTrap;
import tp.pr5.mv.traps.WithoutOperandsEx;

public class DUP extends Instruction {

	
	public DUP() { // Constructor por defecto
		
		op = Opcode.DUP;
		
	}
	
	public void execute(OperandStack stack, Memory mem, ProgramCounter pc, InMethod inMethod, OutMethod outMethod) throws MVTrap {

		if ( stack.isEmpty() )    // Necesitamos al menos un operando en la pila.
			throw new WithoutOperandsEx( this, stack.getCounter() );
		

		stack.push(stack.top());    // Depositamos en la pila el valor que está
		
	}	
	
}
